#include "../source/server.hpp"
#include <string>
using namespace std;

void bufferTest1()
{
    std::string s = "hello!";
    Buffer bf(10);
    for (int i = 0; i < 2; ++i)
    {
        string tmp = s + to_string(i) + '\n';
        bf.write(tmp);
        cout << tmp << "write done" << endl;
    }
    string res = bf.read(string("hello!0\n").size());
    cout << res << endl;
    for (int i = 2; i < 100; ++i)
    {
        string tmp = s + to_string(i) + '\n';
        bf.write(tmp);
    }
    res = bf.read(bf.getReadAbleSize());
    cout << res << endl;
}

void bufferTest2()
{
    int a = 1001;
    Buffer bf(10);
    bf.write(&a, sizeof a);
    int b;
    bf.read(&b, sizeof b);
    cout << b << endl;
}

void bufferTest3()
{
    std::string s = "hello!";
    Buffer bf(10);
    for (int i = 0; i < 100; ++i)
    {
        string tmp = s + to_string(i) + '\n';
        bf.write(tmp);
        // cout << tmp << "write done" << endl;
    }
    while ((s = bf.getline()).size())
        cout << s;
}

int main()
{
    bufferTest1();
    bufferTest2();
    // bufferTest3();
    return 0;
}